$(function() {
    $.ajaxPrefilter(function(options) {
        // console.log(options.url);
        options.url = 'http://api-breakingnews-web.itheima.net' + options.url
        if (options.url.indexOf('/my/') !== -1) {
            options.headers = {
                Authorization: localStorage.getItem('token') || ''
            }
        }
        options.complete = function(res) {
            //不论请求成功还是失败都会调用complete函数
            // console.log('执行了complete函数');
            // console.log(res);
            if (res.responseJSON.status === 1 && res.responseJSON.message === "身份认证失败！") {
                localStorage.removeItem('token')
                location.href = '/login.html'
            }
        }
    })
})